namespace SinaFinanceBaseClassLibrary
{
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Input;
    using System.Windows.Media;

    public class AxisSysTimeSharing : UserControl
    {
        private TimeSharingLine averageLine = new TimeSharingLine();
        private Dictionary<string, List<TimeSharingPoint>> AveragePointDic = new Dictionary<string, List<TimeSharingPoint>>();
        private List<TimeSharingPoint> averagePoints;
        private double bottomSpan = 0.0;
        private Color color1 = new Color();
        private Color color2 = new Color();
        private Image coreImage = new Image();
        private string currentStockID = string.Empty;
        private const int DEF_YAXISMARKCOUNT = 8;
        private const int highZindex = 20;
        private double leftSpan = 0.0;
        private List<string> leftYAxisTips = new List<string>();
        private List<TimeSharingLine> LineInCanvas = new List<TimeSharingLine>();
        private const int lowZindex = 10;
        private Canvas parentCanvas;
        private List<TimeSharingLine> percentLines = new List<TimeSharingLine>();
        private Dictionary<string, List<TimeSharingPoint>> percentPoints;
        public Point pointLeftBottom = new Point();
        public Point pointLeftTop = new Point();
        public Point pointRightBottom = new Point();
        public Point pointRightTop = new Point();
        private double rightSpan = 0.0;
        private List<string> rightYAxisTips = new List<string>();
        private bool showCrossLine = false;
        private TimeSharingLine timeSharingLine = new TimeSharingLine();
        private Dictionary<string, List<TimeSharingPoint>> TimeSharingPointDic = new Dictionary<string, List<TimeSharingPoint>>();
        private List<TimeSharingPoint> timeSharingPoints;
        private double topSpan = 0.0;
        private List<string> xAxisTips = new List<string>();
        private double xAxisUnitLen = 0.0;
        private double yAxisUnitLen = 0.0;

        protected void InitUIParameters()
        {
            this.InitXAxisMarks();
            this.xAxisUnitLen = ((base.Width - this.leftSpan) - this.rightSpan) / ((double) (this.xAxisTips.Count - 1));
            this.yAxisUnitLen = ((base.Height - this.topSpan) - this.bottomSpan) / 8.0;
            this.pointLeftTop = new Point(this.leftSpan, this.topSpan);
            this.pointRightTop = new Point(base.Width - this.rightSpan, this.topSpan);
            this.pointRightBottom = new Point(base.Width - this.rightSpan, base.Height - this.bottomSpan);
            this.pointLeftBottom = new Point(this.leftSpan, base.Height - this.bottomSpan);
        }

        protected void InitXAxisMarks()
        {
            this.xAxisTips.Add("09:30");
            this.xAxisTips.Add("10:00");
            this.xAxisTips.Add("10:30");
            this.xAxisTips.Add("11:00");
            this.xAxisTips.Add("11:30");
            this.xAxisTips.Add("13:30");
            this.xAxisTips.Add("14:00");
            this.xAxisTips.Add("14:30");
            this.xAxisTips.Add("15:00");
        }

        protected void parentCanvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.showCrossLine = !this.showCrossLine;
            if (!this.showCrossLine)
            {
                this.timeSharingLine.RemoveCrossLine();
            }
            else
            {
                Point position = e.GetPosition(this.parentCanvas);
                double x = position.X;
                double y = position.Y;
                int num3 = 0;
                IEnumerator enumerator = (IEnumerator) this.TimeSharingPointDic.Keys.GetEnumerator();
                if (enumerator.MoveNext() && num3.Equals(0))
                {
                    this.timeSharingLine.PointList = this.TimeSharingPointDic[enumerator.Current.ToString()];
                }
                this.timeSharingLine.RenderCrossLine(position);
            }
        }

        private void parentCanvas_MouseMove(object sender, MouseEventArgs e)
        {
            if (this.showCrossLine)
            {
                Point position = e.GetPosition(this.parentCanvas);
                double x = position.X;
                double y = position.Y;
                int num3 = 0;
                IEnumerator enumerator = (IEnumerator) this.TimeSharingPointDic.Keys.GetEnumerator();
                if (enumerator.MoveNext() && num3.Equals(0))
                {
                    this.timeSharingLine.PointList = this.TimeSharingPointDic[enumerator.Current.ToString()];
                }
                this.timeSharingLine.RenderCrossLine(position);
            }
        }

        public void RemoveLineObj()
        {
            this.timeSharingLine.RemoveCrossLine();
            for (int i = 0; i < this.LineInCanvas.Count; i++)
            {
                this.LineInCanvas[i].RemoveLineObj(PointTypeEnum.TimeSharing);
            }
        }

        protected void RenderAxisFramework()
        {
            new AxisSysFramework { ParentCanvas = this.parentCanvas, PointLeftTop = this.pointLeftTop, PointRightTop = this.pointRightTop, PointRightBottom = this.pointRightBottom, PointLeftBottom = this.pointLeftBottom, XAxisUnitLen = this.xAxisUnitLen, YAxisUnitLen = this.yAxisUnitLen, XAxisMarkCount = this.xAxisTips.Count, YAxisMarkCount = 8, ControlZindex = 20 }.RenderAxisSysFramework();
            LinearGradientBrush brush = new LinearGradientBrush();
            GradientStop stop = new GradientStop();
            GradientStop stop2 = new GradientStop();
            stop.Color = Color.FromArgb(0xff, 0, 0, 0);
            stop.Offset = 0.0;
            stop2.Color = Color.FromArgb(0xff, 0x13, 0x1b, 0x29);
            stop2.Offset = 1.0;
            brush.StartPoint = new Point(0.0, 0.0);
            brush.EndPoint = new Point(0.0, 1.0);
            brush.GradientStops.Add(stop);
            brush.GradientStops.Add(stop2);
        }

        protected void RenderAxisMarks()
        {
            AxisSysMarks marks = new AxisSysMarks {
                ParentCanvas = this.parentCanvas
            };
            marks.DrawAxisMarks(this.leftSpan, base.Height - this.bottomSpan, this.xAxisUnitLen, this.xAxisTips, XorYAxisEnum.xAxis);
            marks.DrawAxisMarks(this.leftSpan, this.topSpan, this.yAxisUnitLen, this.leftYAxisTips, XorYAxisEnum.leftYaxis);
            marks.DrawAxisMarks(base.Width - this.rightSpan, this.topSpan, this.yAxisUnitLen, this.rightYAxisTips, XorYAxisEnum.rightYaxis);
            marks.ControlZindex = 20;
        }

        public void RenderAxisSys(bool IsTimeSharingLine)
        {
            this.InitUIParameters();
            this.RenderAxisFramework();
            this.RenderAxisMarks();
            int num = 0;
            if (IsTimeSharingLine)
            {
                this.TimeSharingPointDic.Clear();
                this.TimeSharingPointDic.Add(Guid.NewGuid().ToString(), this.timeSharingPoints);
                IEnumerator enumerator = (IEnumerator) this.TimeSharingPointDic.Keys.GetEnumerator();
                this.timeSharingLine.CurrentStockID = this.currentStockID;
                this.timeSharingLine.CoreImage = this.coreImage;
                if (enumerator.MoveNext() && num.Equals(0))
                {
                    this.RenderLineObj(this.timeSharingLine, this.TimeSharingPointDic[enumerator.Current.ToString()], PointTypeEnum.TimeSharing, Color.FromArgb(0xff, 30, 0x90, 0xff));
                }
                this.AveragePointDic.Clear();
                this.AveragePointDic.Add(Guid.NewGuid().ToString(), this.averagePoints);
                IEnumerator enumerator2 = (IEnumerator) this.AveragePointDic.Keys.GetEnumerator();
                if (enumerator2.MoveNext() && num.Equals(0))
                {
                    this.RenderLineObj(this.averageLine, this.AveragePointDic[enumerator2.Current.ToString()], PointTypeEnum.Average, Colors.White);
                }
                this.parentCanvas.MouseMove += new MouseEventHandler(this.parentCanvas_MouseMove);
                this.parentCanvas.MouseLeftButtonDown += new MouseButtonEventHandler(this.parentCanvas_MouseLeftButtonDown);
            }
            else
            {
                IEnumerator enumerator3 = (IEnumerator) this.percentPoints.Keys.GetEnumerator();
                for (int i = 0; enumerator3.MoveNext(); i++)
                {
                    string str = enumerator3.Current.ToString();
                    TimeSharingLine line = new TimeSharingLine();
                    List<TimeSharingPoint> pointDic = this.percentPoints[str];
                    Color color = new Color();
                    if (i.Equals(0))
                    {
                        color = this.color1;
                    }
                    else
                    {
                        color = this.color2;
                    }
                    this.RenderLineObj(line, pointDic, PointTypeEnum.Percent, color);
                }
            }
        }

        public void RenderLineObj(TimeSharingLine line, List<TimeSharingPoint> pointDic, PointTypeEnum pointTypeEnum, Color color)
        {
            line.ParentCanvas = this.parentCanvas;
            line.PointLeftTop = this.pointLeftTop;
            line.PointRightTop = this.pointRightTop;
            line.PointRightBottom = this.pointRightBottom;
            line.PointLeftBottom = this.pointLeftBottom;
            line.XAxisUnitLen = this.xAxisUnitLen;
            line.YAxisUnitLen = this.yAxisUnitLen;
            line.XaxisDatalist = this.xAxisTips;
            line.LeftYaxisDatalist = this.leftYAxisTips;
            line.RightYaxisDatalist = this.rightYAxisTips;
            line.PointList = pointDic;
            line.LineColor = color;
            line.ControlZindex = 10;
            line.RenderLine(pointTypeEnum);
            this.LineInCanvas.Add(this.timeSharingLine);
        }

        public List<TimeSharingPoint> AveragePoints
        {
            get
            {
                return this.averagePoints;
            }
            set
            {
                this.averagePoints = value;
            }
        }

        public double BottomSpan
        {
            get
            {
                return this.bottomSpan;
            }
            set
            {
                this.bottomSpan = value;
            }
        }

        public Color Color1
        {
            get
            {
                return this.color1;
            }
            set
            {
                this.color1 = value;
            }
        }

        public Color Color2
        {
            get
            {
                return this.color2;
            }
            set
            {
                this.color2 = value;
            }
        }

        public Image CoreImage
        {
            get
            {
                return this.coreImage;
            }
            set
            {
                this.coreImage = value;
            }
        }

        public string CurrentStockID
        {
            get
            {
                return this.currentStockID;
            }
            set
            {
                this.currentStockID = value;
            }
        }

        public double LeftSpan
        {
            get
            {
                return this.leftSpan;
            }
            set
            {
                this.leftSpan = value;
            }
        }

        public List<string> LeftYAxisTips
        {
            get
            {
                return this.leftYAxisTips;
            }
            set
            {
                this.leftYAxisTips = value;
            }
        }

        public Canvas ParentCanvas
        {
            get
            {
                return this.parentCanvas;
            }
            set
            {
                this.parentCanvas = value;
            }
        }

        public Dictionary<string, List<TimeSharingPoint>> PercentPoints
        {
            get
            {
                return this.percentPoints;
            }
            set
            {
                this.percentPoints = value;
            }
        }

        public double RightSpan
        {
            get
            {
                return this.rightSpan;
            }
            set
            {
                this.rightSpan = value;
            }
        }

        public List<string> RightYAxisTips
        {
            get
            {
                return this.rightYAxisTips;
            }
            set
            {
                this.rightYAxisTips = value;
            }
        }

        public List<TimeSharingPoint> TimeSharingPoints
        {
            get
            {
                return this.timeSharingPoints;
            }
            set
            {
                this.timeSharingPoints = value;
            }
        }

        public double TopSpan
        {
            get
            {
                return this.topSpan;
            }
            set
            {
                this.topSpan = value;
            }
        }

        public List<string> XAxisTips
        {
            get
            {
                return this.xAxisTips;
            }
            set
            {
                this.xAxisTips = value;
            }
        }
    }
}
